package com.iss.efi.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iss.efi.dto.Efi074;
import com.iss.efi.dto.Efi075;
import com.iss.efi.dto.ResultDto;
import com.iss.efi.mapper.Efi074Mapper;
import com.iss.efi.mapper.Efi078Mapper;
import com.iss.efi.service.Efi075Service;
import com.iss.efi.mapper.Efi075Mapper;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author songyong
* @description 针对表【EFI075】的数据库操作Service实现
* @createDate 2024-02-02 17:00:09
*/
@Service
public class Efi075ServiceImpl extends ServiceImpl<Efi075Mapper, Efi075>
    implements Efi075Service{

    @Resource
    private SqlSessionFactory sqlSessionFactory;

    @Override
    public ResultDto receive(JSONObject params) {
        ResultDto resultDto = new ResultDto("00","操作成功");
        Efi074 efi074=   params.getObject("main",Efi074.class);
        List<Efi075> efi075List =params.getList("list",Efi075.class);

        SqlSession batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
        try {
            QueryWrapper queryWrapper=  new QueryWrapper<Efi074>().eq("BLNO",efi074.getBLNO());

            Efi074Mapper efi074Mapper=  batchSqlSession.getMapper(Efi074Mapper.class);
            if (efi074Mapper.selectCount(queryWrapper)>0){
              return new ResultDto("00","订单号已存在");
            }
            Efi075Mapper efi075Mapper=  batchSqlSession.getMapper(Efi075Mapper.class);
            efi074Mapper.insert(efi074);
            for(Efi075 efi075:efi075List){
                efi075Mapper.insert(efi075);
            }
            batchSqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
            batchSqlSession.rollback();
            return new ResultDto("E03","保存数据出错");
        } finally {
            batchSqlSession.close();
        }
        return resultDto;
    }
}




